<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\batch;

use app\enum\ConfigEnum;
use app\enum\KuaiShouEnum;
use app\service\BaseService;
use think\facade\Cache;

class BatchService extends BaseService
{
    /**
     * 存redis处理创意素材队列.
     * @param array $contentIds 内容id
     * @return bool
     */
    public static function pushKsMaterialList(array $contentIds = []): bool
    {
        $redis = Cache::store('redis')->handler();
        foreach ($contentIds as $id) {
            $redis->rPush(ConfigEnum::CACHE_CONFIG[KuaiShouEnum::BATCH_CONFIG_KEY]['batch_material'], $id);
        }
        return true;
    }

    /**
     * 存redis推送创意队列.
     * @param int $contentId 内容id
     */
    public static function pushKsCreativeList(int $contentId = 0): bool
    {
        Cache::store('redis')->handler()->rPush(ConfigEnum::CACHE_CONFIG[KuaiShouEnum::BATCH_CONFIG_KEY]['batch_creative'], $contentId);
        return true;
    }

    /**
     * 存redis推送计划队列.
     * @param array $contentIds 内容id
     */
    public static function pushKsCampaignList(array $contentIds = []): bool
    {
        $redis = Cache::store('redis')->handler();
        foreach ($contentIds as $id) {
            $redis->rPush(ConfigEnum::CACHE_CONFIG[KuaiShouEnum::BATCH_CONFIG_KEY]['batch_campaign'], $id);
        }
        return true;
    }

    /**
     * 存redis推送广告组队列.
     * @param array $contentIds 内容id
     */
    public static function pushKsUnitList(array $contentIds = []): bool
    {
        $redis = Cache::store('redis')->handler();
        foreach ($contentIds as $id) {
            $redis->rPush(ConfigEnum::CACHE_CONFIG[KuaiShouEnum::BATCH_CONFIG_KEY]['batch_unit'], $id);
        }
        return true;
    }
}
